package controllers

import (
	"map/libs"
	"map/models"
)

type LoginController struct {
	BaseController
}

func (this *LoginController) Login() {
	admin, err := models.AdminByUsername(this.GetString("username"))
	if err != nil {
		this.errors("未找到用户名", 1)
	}
	if admin.Password != libs.PasswordMake(this.GetString("password")) {
		this.errors("密码错误", 1)
	}

	this.SetSession("admin", admin.Id)
	this.success("")
}

func (this *LoginController) LogOut() {
	this.DelSession("admin")
	this.success("")
}
